﻿using Md.Api.Entity.ModelDB;

namespace Md.Petapoco.Repositories.MdTrainingEducation;
/// <summary>
/// 系统角色菜单关联仓储
/// </summary>
public class SysRoleMenuRep : BaseRep<SysRoleMenuModel>
{
    /// <summary>
    /// 通过角色编号获取(系统角色菜单关联)列表
    /// </summary>
    /// <param name="roleId">角色编号</param>
    /// <returns>IEnumerable<SysRoleMenuModel></returns>
    public IEnumerable<SysRoleMenuModel> GetSysRoleMenuListByRoleId(long roleId)
    {
        #region ===sql===
        string sqlStr = string.Format(@"
            select `id`
                  ,`role_id`
                  ,`menu_id`
            from `sys_role_menu`
            where 1 = 1 and `role_id` = @0
         ");
        #endregion

        return MdTrainingEducationDB.GetInstance().Query<SysRoleMenuModel>(sqlStr, roleId);
    }
    /// <summary>
    /// 通过角色编号删除(角色菜单关联)数据
    /// </summary>
    /// <param name="roleId">角色编号</param>
    /// <returns>int</returns>
    public int DeleteMenuByRoleId(long roleId)
    {
        string strSql = string.Format(@"
            where 1 = 1 and `role_id` = @0
        ");

        return MdTrainingEducationDB.GetInstance().Delete<SysRoleMenuModel>(strSql, roleId);
    }
}

